﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace F1010DB.ScoutMember
{
    public class ScoutMemberCommon : AbstractGetBridgeConnect
    {
        // -----------------Các constant
        
        // Các sql xử lý
        private const string CHECK_ACTIVE_IN_UNIT = " SELECT MA_DOAN_SINH  FROM HDVNQTRI.DOAN_SINH_MASTER_HISTORY WHERE MA_DOAN_SINH = @madoansinh AND MA_DON_VI = @madonvi AND ACTIVE='1'";
        private const string CHECK_ACTIVE_IN_ACCIENT = " SELECT B.MA_DOAN_SINH, A.HO_LOT + ' ' + A.TEN_DEM + ' ' + A.TEN AS HO_VA_TEN FROM HDVNQTRI.DOAN_SINH_MASTER_HISTORY B INNER JOIN HDVNQTRI.DOAN_SINH_MASTER A ON A.MA_DOAN_SINH = B.MA_DOAN_SINH WHERE  B.MA_DON_VI = @madonvi AND B.ACTIVE='1'";

        /// <summary>
        /// Xác định trạng thái đoàn sinh có sinh hoạt tại đơn vị không
        /// </summary>
        /// <param name="scoutmember"></param>
        /// <param name="unitcode"></param>
        /// <returns></returns>
        public bool checkActiveScout(string scoutmember, string unitcode)
        {
            Dictionary<string, object> objParam = new Dictionary<string, object>();

            objParam.Add("@madoansinh", scoutmember);
            objParam.Add("@madonvi", unitcode);

            DataTable dtTableActiveScout = dbContext.readATable(CHECK_ACTIVE_IN_UNIT, CommandType.Text, objParam);

            if (dtTableActiveScout == null || dtTableActiveScout.Rows.Count > 0)
            {
                return false;
            }

            return true;
        }

        /// <summary>
        /// Lấy danh sách đơn giản
        /// </summary>
        /// <param name="unitcode"></param>
        /// <returns></returns>
        public DataTable getScoutMemberBasicList(string unitcode)
        {
            Dictionary<string, object> objParam = new Dictionary<string, object>();

            objParam.Add("@madonvi", unitcode);

            DataTable dtTableActiveScout = dbContext.readATable(CHECK_ACTIVE_IN_ACCIENT, CommandType.Text, objParam);

            return dtTableActiveScout;
        }
    }
}
